class Person:
    # 构造方法，方法可以默认带有this指针，即self
    def __init__(self, name):
        self.name = name

    def say_hello(self):
        print("hello, {}".format(self.name))


p = Person("tom")
p.say_hello()


class Robot:
    population = 0

    count = 0

    def __init__(self, name):
        self.name = name
        print('{} is been created'.format(self.name))
        Robot.population += 1  # 类似于修改静态变量
        self.count += 1  # 只修改当前对象的变量副本

    def die(self):
        """我挂了。"""
        print("{} is being destroyed!".format(self.name))
        Robot.population -= 1
        if Robot.population == 0:
            print("{} was the last one.".format(self.name))
        else:
            print("There are still {:d} robots working.".format(
                Robot.population))

    # 静态方法
    @classmethod
    def how_many(cls):
        print("we have {} robots".format(Robot.population))


r1 = Robot("aa")
r2 = Robot("bb")

print(r1.count)
print(r2.count)
print(Robot.count)
Robot.how_many()
r1.die()
r2.die()
r1.how_many()

